<html>
    <style type="text/css">
        body {font-family: Helvetica,Arial, sans-serif; font-size: 8pt;}
    </style>
<body>
   <?php
        require_once 'constants.php';
        require_once 'db.php';
        require_once 'feedback.php';

        $errorMessage = "";

        //Make sure the file was uploaded to the server and has the right size
        if ( is_uploaded_file( $_FILES['fuf_file']['tmp_name'] )) {
            if ( $_FILES['fuf_file']['size'] < IMAGE_MAX_FILE_SIZE ) {
                ;
            }
            else {
                $errorMessage = "File size '" . $_FILES['fuf_file']['size'] . "' exceeds the allowed maximum of '" . IMAGE_MAX_FILE_SIZE . "'";
            }
        }
        else {
            $errorMessage = "System error while uploading the file. Temporary upload file not found";
        }

        if ( !$errorMessage ) {
            $row['description'] = $_POST['fuf_description'];
            $row['submit_date'] = date("Y-m-d");
            $row['source'] = $_POST['fuf_source'];
            $row['email'] = $_POST['fuf_email'];
            $row['status'] = IMAGE_STATUS_PENDING;
            $row['publish_date'] = "0000-00-00";
            $row['image'] = addslashes(file_get_contents($_FILES['fuf_file']['tmp_name']));
            $row['comment'] = "No Comment";

            if ( !dbInsertNewImageInfo($row) ) {
                $errorMessage = "Database error occured";
            }
        }

        //Report an error if any was encountered
        if( $errorMessage == "" ) {
            print "Thank you for submitting a new picture. It will be processed within the next 24 hours. The processing status will be sent to the email address you provided";
            notifyUserOfStatusChange($row);
        }
        else {
            print "<span style='color: red'>The following error was encountered while uploading the picture: <i>'" . $errorMessage . "'</i>.</span>";
        }
    ?>
</body>
</html>
